<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;
class Hangyezhanhui extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index(Request $request)
    {
		$this->view->assign('title', __('行业展会'));

		$banner=Db::name('banner')->where([
			'type_data'=>0,
			'bannertype_id'=>16
		])->select();
		$this->assign('banner',$banner);

		$hangyezhanhuitype_type=Db::name('hangyezhanhuitype')->where('show_switch',1)->order('weigh desc')->select();
		$this->assign('hangyezhanhuitype_type',$hangyezhanhuitype_type);

		$hangyexinxi_type2=Db::name('hangyexinxitype')->where(['id'=>['>',1],'show_switch'=>1])->order('weigh desc')->limit(3)->select();
		foreach($hangyexinxi_type2 as $k=>$v){
			$hangyexinxi_type2[$k]['list']=Db::name('hangyexinxi')->where(['type_id'=>$v['id']])->order('weigh desc')->limit(4)->select();
		}
		$this->assign('hangyexinxi_type2',$hangyexinxi_type2);

		$type=$request->param('type/d',0);
		if($type==0){
			$type=$hangyezhanhuitype_type[0]['id'];
		}
		$this->assign('type',$type);

		$today=date('Y-m-d');
		$list=Db::name('hangyezhanhui')->where('hangyezhanhuitype_id',$type)->orderRaw("ABS(DATEDIFF(start_date, '$today'))")->paginate(15);

		$this->assign('list',$list);

        return $this->view->fetch();
    }

	public function detail(Request $request)
	{
		$id=$request->param('id/d',0);
		$rs=Db::name('hangyezhanhui')->where('id',$id)->find();
		if(is_null($rs)){
			$this->error('内容不存在');
		}
		$this->assign('rs',$rs);
		$this->view->assign('title', __('行业展会-').$rs['name']);
		$this->assign('image',input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME').$rs['image']);
	    return $this->view->fetch();
	}
}
